<?php
/**
 * Validate user input
 * 
 * @author anhtt
 * @copyright $Id$
 * @package modules/form
 * @subpackage modules/form/validate
 */
class Admin_Library_Validate_ValidateUserInput extends Zend_Validate_Abstract
{
	const INVALID_INPUT = 'invalidInput';
	const INVALID_START = 'invalidStartLetter';

	/**
	 * Construction
	 *
	 */
	public function __construct()
	{
	}

	/**
	 * Check if userlogin is valid
	 *
	 * @param string $userLogin
	 * @return boolean
	 * @see library/Zend/Validate/Zend_Validate_Interface::isValid()
	 */
	public function isValid($userLogin)
	{
		if (!is_string($userLogin)) {
			$this->_error(self::INVALID_INPUT);
			return FALSE;
		}
		
		$filter = preg_replace('/[a-zA-Z0-9_\.\-]/', '', $userLogin);

		if ($filter !== '') {
			$this->_error(self::INVALID_INPUT);
		}
		
		$startLetterValidate = new Zend_Validate_Alpha(); 
		if (!$startLetterValidate->isValid(substr($userLogin, 0, 1))) {
			$this->_error(self::INVALID_START);
		}

		if (count($this->_messages)) {
			return FALSE;
		} else {
			return TRUE;
		}
	}
}